# # 打开文件open（）读取文件read（）
# import pandas as pd
#
# f = open('1.txt', 'r', encoding='utf-8')
# print(f.read())
# # 2
# with open('1.txt', 'r', encoding='utf-8') as file:
#     text = file.read()
# print(text)
# # 3.绝对路径
# ff = open(r'C:\Users\Administrator\Desktop\2.txt', encoding='utf-8')
# print(ff.read())
# # 写文件
# fff = open('3.txt', 'w', encoding='utf-8')
# fff.write('hello world,hello china')
# date = '你好，今天星期四'
# fff.close()
# with open('3.txt', 'w', encoding='utf-8') as f:
#     f.write(date)
import pandas as pd
# import requests
# import scrapy
import openpyxl
# # 读取Excel表格，获取一个dateframe对象
# df = pd.read_excel(r'C:\Users\Administrator\Desktop\1.xlsx')
# print(df)
# 写文件到excel
a1 = {'name': 'xiaohong', 'age': 20}
a2 = {'name': 'xiaoxue', 'age': 18}
a3 = {'name': 'xiaowang', 'age': 19}
l = [a1, a2, a3]
print(l)
# 需要将列表变成DateFrame格式
df1 = pd.DataFrame(l)
print(df1)
# 使用pandas的函数to_excle(),index索引
df1.to_excel('2.xlsx', index=False)
# 处理word文档，需要下载Python-docx
# 导入docx库Document模块
from docx import Document
doc = Document()
p = doc.paragraphs
print(p)
print(len(p))
for i in p:
    print(i.text)